/**
 * 底纹和水印设置
 * @param opt 
 */
function scWatermarkSetting(opt) {
    opt = opt ? opt : {};

    var com = scCommon.instance();
    var crEle = com.crEle;

    var tab = new scTabx();

    /**
     * 水印属性
     */
    var waterItems = [
        { label: "显示文本：", value: "content", type: "input", placeholder: "必填" },
        { label: "文本颜色：", value: "style.color", type: "dropdown", display:"color", component: "scColorpickerSetting",
            param: {color: "#ddd"}
        },
        {
            label: "字体类型：", value: "style.fontFamily", type: "select",
            list: ["Arial", "宋体", "微软雅黑", "仿宋", "楷体", "隶书", "幼圆", "华文彩云", "华文行楷"]
        },
        {
            label: "字体大小：", value: "style.fontSize", type: "select",
            list: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 35, 40, 45, 50, 55, 60]
        },
        { label: "显示行数：", type: "component", component: "scNumber",
            param: {name: "rowcount", minNum: 1, maxNum: 10, value: 1} 
        },
        { label: "显示列数：", type: "component", component: "scNumber",
            param: {name: "colcount", minNum: 1, maxNum: 10, value: 1} 
        },
        { label: "旋转角度：", type: "component", component: "scNumber",
          param: {name: "style.rotate", minNum: -360, maxNum: 360, value: 0} 
        },
    ];

    /**
     * 底纹属性
     */
    var textureItems = [
        { label: "背景颜色：", value: "style.backgroundColor", type: "dropdown", display:"color", component: "scColorpickerSetting",
            param: {color: "#fff"}
        },
        { label: "选择图片：", value: "image", type: "file", accept: "image/*"}
    ];

    /**
     * 容器
     */
    var box = null;

    /**
     * 创建视图
     */
    this.createView = function (option) {
        box = crEle(null, "sc-watermark-setting");

        var listener = option ? option.listener : null;
        var optW = {...opt};
        var optT = {...opt};

        if(listener){
            optW.data = listener("getWatermark");
            optT.data = listener("getTexture");
        }

        box.appendChild(tab.createView({
            menus: [
                {
                    label: "水印",
                    value: "",
                    selected: true,
                    component: {
                        createView: createWatermarkView.call(this, optW)
                    }
                },
                {
                    label: "底纹",
                    value: "",
                    component: {
                        createView: createBackView.call(this, optT)
                    }
                }
            ]
        }));

        return box;
    }

    /**
     * 创建底纹设置视图
     * @param {*} node
     */
    var createBackView = function (opt) {
        return () => {
            var data = opt ? opt.data : null;
            var wrap = crEle("div", "sc-texture-view");

            com.insertNode(textureItems, data, wrap, "sc-watermark-setting-row");

            return wrap;
        }
    }

    /**
     * 创建水印设置视图
     * @param {*} node 
     */
    var createWatermarkView = function (opt) {
        return () => {
            var data = opt ? opt.data : null;
            var wrap = crEle("div", "sc-watermark-view");

            com.insertNode(waterItems, data, wrap, "sc-watermark-setting-row");

            return wrap;
        }
    }

    /**
     * 获取设置后的数据
     */
    this.getData = function () {
        return com.getData(box, (data)=>{
            if(tab.getSelectedName() == "底纹"){
                data.$command = "insertTexture";
            }
        });
    }

    /**
     * 通知
     * @param {*} eventType 
     * @param {*} param 
     */
    this.notify = function (eventType, param) {
    }
}